# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get

# Binary names
BINARY_NAME=webappd

# Release Path 
RELEASE_PATH=release

# Postgresql
DB_URL='postgres://Jonathan:postgres@127.0.0.1/webapi?sslmode=disable'

# index 
INDEX='./src/main.go'

build: 
	$(GOBUILD) -o $(BINARY_NAME) -v $(INDEX)

clean: 
	rm -f ./$(BINARY_NAME)

start:
	make build && ./$(BINARY_NAME) ./config.toml

test:
	make start & \
	cd tools/apitest && npm test && \
	pkill -f $(BINARY_NAME)

# build release for linux/darwin
publish:
	rm -rf release && mkdir -p release && \
	CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 \
	$(GOBUILD) -o $(RELEASE_PATH)/darwin/$(BINARY_NAME) -v $(INDEX) && \
	cp config.toml $(RELEASE_PATH)/darwin/ && \
	CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
	$(GOBUILD) -o $(RELEASE_PATH)/unix/$(BINARY_NAME) -v $(INDEX) && \
	cp config.toml $(RELEASE_PATH)/unix



# migration
db-setup:
	cd migrations && goose postgres $(DB_URL) up
db-reset:
	cd migrations && goose postgres $(DB_URL) down-to 0 && goose postgres $(DB_URL) up

docs-gen:
	apidoc  -i src/ -o docs/